﻿using ComponentFactory.Krypton.Toolkit;
using Nini.Config;
using System;
using System.Windows.Forms;

namespace TfsHelper.WinFrontEnd
{
    public partial class frmTfsUrl : KryptonForm
    {
        #region " Fields "

        public static IConfigSource config = new XmlConfigSource(Application.StartupPath + "\\Config.xml");

        #endregion

        #region " Constructor "

        public frmTfsUrl()
        {
            InitializeComponent();
        }

        #endregion

        #region " Event Handlers "

        private void frmTfsUrl_Load(object sender, EventArgs e)
        {
            txtUrl.Text = config.Configs["General"].Get("TfsUrl");
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (!Uri.IsWellFormedUriString(txtUrl.Text, UriKind.Absolute))
            {
                KryptonMessageBox.Show("The Url specified is not valid.", "Invalid Url", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            config.Configs["General"].Set("TfsUrl", txtUrl.Text);
            config.Save();
            DialogResult = System.Windows.Forms.DialogResult.OK;
            KryptonMessageBox.Show("The Url was changed correctly.", "Url", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
            Close();
        }

        #endregion
    }
}
